<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>记账本</title>
    <link rel="stylesheet" href="../js/element-ui-2.13.0/lib/theme-chalk/index.css">
    <style>
        #whole {
            margin: 0 auto;
            width: 500px;
            height: 500px;
            display: flex;
            justify-content: center; /*实现水平居中*/
            align-items: center; /*实现垂直居中*/
            top: 50%;
            left: 50%;
            position: absolute;
            margin: -250px 0 0 -250px;
            background: #409EFF;
        }

        body {
            background: #409EFF;
        }

        button{
            height: 80px;
            width: 500px;
        }
    </style>
    <script src="../js/vue.js"></script>
    <script src="../js/element-ui-2.13.0/lib/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body>
<div id="whole">
    <div>
        <el-link type="info" href="../options/options.html">回到首页<i class="el-icon-view el-icon--right"></i> </el-link>
        <br>
        <h1 style="width: 500px;color: white">欢迎，亲爱的<i>{{ruleForm.realName}}</i></h1>
        <h2 style="color:gold;">您今天已消费：{{consumptionAmount}}</h2>
        <el-divider></el-divider>
        <el-button class="button" type="success" @click="addBill"><h1>新增账单</h1></el-button>
        <br><br>
        <el-button class="button" type="success" @click="manageBill"><h1>账单分类</h1></el-button>
        <br><br>
        <el-button class="button" type="success" @click="accountInformation"><h1>账户信息</h1></el-button>
        <br><br>
        <el-button class="button" type="success" @click="queryBill"><h1>账单查询</h1></el-button>
        <br><br>
        <el-button class="button" type="success" @click="countBill"><h1>账单统计</h1></el-button>
    </div>
</div>
</body>
<script>
    const app = new Vue({
        el: '#whole',
        data: {
            ruleForm: {
                username: "",
                realName: "",
                startTime:""
            },
            consumptionAmount:""
        },
        methods: {
            addBill(){
                window.location.href="addBill.html";
            },
            queryBill(){
                window.location.href="queryBill.html";
            },
            dealCookie(){
                // 对cookie操作
                var cookies = document.cookie;
                var cookie_array = cookies.split(";");
                for(var i = 0;i < cookie_array.length;i++){
                    var cookie = cookie_array[i];
                    var array = cookie.split("=");
                    if(array[0] == "realName"){
                        this.ruleForm.realName = array[1];
                    }
                    if (array[0] == " username"){
                        this.ruleForm.username = array[1];
                    }
                }
            },
            getDate() {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth()+1;
                if (month < 10) {
                    month = "0" + month;
                }
                var day = date.getDate();
                if (day < 10) {
                    day = "0" + day;
                }
                var hour = date.getHours();
                if (hour < 10) {
                    hour = "0" + hour;
                }
                var minute = date.getMinutes();
                if (minute < 10) {
                    minute = "0" + minute;
                }
                var second = date.getSeconds();
                if (second < 10) {
                    second = "0" + second;
                }
                this.ruleForm.startTime = year + "-" + month + "-" + day + " " + "00:00:00";
            },
            queryConsumptionAmount(){
                this.getDate();
                axios.post('https://3723r72n06.picp.vip/mylife/bill/queryConsumptionAmount', this.ruleForm, {headers: {'conTent-Type': 'application/json'}}).then(response => {
                    this.consumptionAmount = response.data;
                });
            },
            manageBill(){
                window.location.href="manageBill.html";
            },
            countBill(){
                window.location.href="countBill.html";
            },
            accountInformation(){
                window.location.href="accountInformation.html";
            }
        },
        mounted(){
            this.dealCookie();
            this.queryConsumptionAmount();
        },
    });
</script>
</html>